package cn.wolfcode.luowowo.search.qo;

import cn.wolfcode.luowowo.common.query.QueryObject;
import lombok.Getter;
import lombok.Setter;
import org.elasticsearch.search.aggregations.metrics.geobounds.InternalGeoBounds;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

@Getter
@Setter
public class IndexSearchQo extends QueryObject{
    private String type;
    private String orderBy="viewnum";

    public static final int SEARCH_TYPE_DEST = 0;   //目的地
    public static final int SEARCH_TYPE_STRATEGY = 1;   //攻略
    public static final int SEARCH_TYPE_TRAVEL = 2;   //游记
    public static final int SEARCH_TYPE_USER = 3;   //用户


    public String getIndex() {
        switch (getType()) {
            case "0":
                return "luowowo_destination";
            case "1":
                return "luowowo_strategy";
            case "2":
                return "luowowo_travel";
            case "3":
                return "luowowo_userinfo";
        }
        return null;
    }

    public String getTrueType () {
        switch (getType()) {
            case "0":
                return "destination";
            case "1":
                return "strategy";
            case "2":
                return "travel";
            case "3":
                return "userinfo";
        }
        return null;
    }

    public Pageable getPageable() {
        if(getType().equals("0")||getType().equals("3")) {
            return PageRequest.of(getCurrentPage()-1,getPageSize());
        }
        return PageRequest.of(getCurrentPage()-1,getPageSize(), Sort.Direction.DESC,getOrderBy());
    }
}
